package jing.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.aspectj.org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import jing.mapper.UserInfoCustomMapper;
import jing.mapper.UserInfoMapper;
import jing.pojo.UserInfo;
import jing.pojo.UserInfoCustom;
import jing.pojo.UserInfoVo;
import jing.service.UserInfoService;

public class UserInfoServiceImpl implements UserInfoService {

	@Autowired
	private UserInfoCustomMapper userInfoCustomMapper;

	@Autowired
	private UserInfoMapper userInfoMapper;

	@Override
	public List<UserInfoCustom> selectUserInfo(UserInfoVo userInfoVo) throws Exception {
		return this.userInfoCustomMapper.selectUserInfo(userInfoVo);
	}

	@Override
	public UserInfoCustom selectUserInfoById(Integer id) throws Exception {
		UserInfoCustom usCustom = new UserInfoCustom();
		UserInfo userInfo = this.userInfoMapper.selectByPrimaryKey(id);
		// 将userInfo中的属性复制到usCustom中，由Spring提供的此方法
		BeanUtils.copyProperties(userInfo, usCustom);
		return usCustom;
	}

	@Override
	public void updateUserInfo(Integer id, UserInfoCustom userInfoCustom) throws Exception {
		userInfoCustom.setId(id);
		this.userInfoMapper.updateByPrimaryKey(userInfoCustom);
	}

	@Override
	public List<UserInfoCustom> selectUserInfoByArray(String[] userInfo) throws Exception {
		UserInfoVo userInfoVo = new UserInfoVo();
		UserInfoCustom userInfoCustom = new UserInfoCustom();
		if (userInfo!=null) {
			userInfoCustom.setPhone(userInfo[0].toString());
			userInfoCustom.setIdcard(userInfo[1].toString());
		}
		userInfoVo.setUserInfoCustom(userInfoCustom);
		List<UserInfoCustom> listUserInfo = this.userInfoCustomMapper.selectUserInfoByArray(userInfoVo);
		return listUserInfo;
	}
	
}
